﻿using MediatR;
using SystemWFH.API.Application.Command.ProductionPlanningCommand;
using SystemWFH.Infrstructer.Impl;
using SystemWFH.Infrstructer.Interface;

namespace SystemWFH.API.Application.CommandHandlers.ProductionPlanningCommandHandler
{
    public class ProductionPlanningDeleteCommandHandler : IRequestHandler<ProductionPlanningDeleteCommand, int>
    {
        private readonly IProductionPlanningRepository productionPlanning;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="productionPlanning">上下文对象</param>
        public ProductionPlanningDeleteCommandHandler(IProductionPlanningRepository productionPlanning)
        {
            this.productionPlanning = productionPlanning;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<int> Handle(ProductionPlanningDeleteCommand request, CancellationToken cancellationToken)
        {
            var list = await productionPlanning.GetValue(request.productionId);
            list.IsDelete = true;
            list.DelectTime = DateTime.Now.ToUniversalTime();
            list.DelectName = "李明";
            return await productionPlanning.UpdateAsync(list);
        }
    }
}
